home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11750 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  77 lines

  1. Path: tudelft.nl!news
  2. From: Ejo Schrama <schrama@geo.tudelft.nl>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A garbage collection problem in C++
  5. Date: 15 Mar 1996 15:58:52 GMT
  6. Organization: TU Delft, Faculty of Geodetic Engineering
  7. Message-ID: <4ic43s$k0@mo6.rc.tudelft.nl>
  8. References: <4ic3vb$k0@mo6.rc.tudelft.nl>
  9. NNTP-Posting-Host: dutgs7.geo.tudelft.nl
  10. Mime-Version: 1.0
  11. Content-Type: multipart/mixed;
  12.     boundary="-------------------------------263031712011091"
  13. X-Mailer: Mozilla 1.12 (X11; I; HP-UX A.09.05 9000/735)
  14. X-URL: file:/users/schrama/work/dingo/work/test.cc
  15.  
  16. This is a multi-part message in MIME format.
  17.  
  18. ---------------------------------263031712011091
  19. Content-Transfer-Encoding: 7bit
  20. Content-Type: text/plain; charset=us-ascii
  21.  
  22. Ejo Schrama <schrama@geo.tudelft.nl> wrote:
  23. >This is a multi-part message in MIME format.
  24. >
  25. >---------------------------------9580122325627
  26. >Content-Transfer-Encoding: 7bit
  27. >Content-Type: text/plain; charset=us-ascii
  28. >
  29. >I noticed a garbage collection problem with the following program.
  30. >If you decide to delete arrays then we all know that 
  31. >
  32. >  double *a; 
  33. >  a = new double[1000];
  34. >  delete[] a;
  35. >
  36. >works. However the following code shows that the delete[] operator
  37. >will only treat the first argument as an array, the second argument
  38. >is not. It sounds like a easter-egg....
  39. >
  40. >Ejo (http://www.geo.tudelft.nl/fmr/people/schrama.html)
  41. >
  42.  
  43. I rather had the following code in mind, forget previous posting
  44.  
  45. ---------------------------------263031712011091
  46. Content-Transfer-Encoding: 7bit
  47. Content-Type: text/plain
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51.  
  52. main()
  53. {
  54.   double *a,*b;
  55.   a = new double[1000];
  56.   b = new double[1000];
  57.   //
  58.   // OPTION1: causes 8008 bytes of garbage on the heap
  59.   //
  60.   #ifdef OPTION1
  61.   delete[] a,b;
  62.   #endif
  63.   //
  64.   // OPTION2: cleans up the heap
  65.   //
  66.   #ifdef OPTION2
  67.   delete[] a;
  68.   delete[] b;
  69.   #endif
  70.   //
  71.   // Under HP-UX the following will show a memory map
  72.   //
  73.   memorymap(0);
  74. }
  75.  
  76. ---------------------------------263031712011091--
  77.